package com.tmall.testgen.plugin.wizards.runinspring;

import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

/**
 * 
 * 
 * @author liuzx
 */
public class FileSelectionWizard extends Wizard implements INewWizard {
	private ISelection selection;
	private MyWizardSelectFilePage page;
	StringBuilder dest = new StringBuilder();
	String serviceName, projectName;
	int flag;
	IFolder serviceFolder;

	/**
	 * 
	 */
	public FileSelectionWizard(boolean isFileFilter) {
		page = new MyWizardSelectFilePage("name", null,isFileFilter);
		setWindowTitle("New adapterService Wizard");
		addPage(page);
	}

	private String filePath;
	private String projectPath;
	private IProject project;

	public String getProjectPath() {
		return projectPath;
	}

	public String getFilePath() {
		return filePath;
	}

	/**
	 * 适配服务创建向导 完成处理
	 */
	@Override
	public boolean performFinish() {
		// // 获取适配工程名和适配服务名
		// serviceName = page.getServiceName();
		// projectName = page.getProjectName();
		// flag = page.getFlag();
		filePath = page.getFilePath();
		projectPath = page.getObjectPath();
		project = page.getSelectedProject();
		return true;
	}

	public IProject getProject() {
		return project;
	}

	/**
	 * 获取将要放置配置文件的文件夹
	 * 
	 * @return
	 */
	public IFolder getServiceFolder(IProject adapterProject) {
		// 获取将要放置配置文件的文件夹路径
		IFolder serviceFolder = adapterProject.getFolder("serviceAdapter");

		// 判断文件夹是否存在，如果不存在则新建文件夹
		if (!serviceFolder.exists()) {
			try {
				serviceFolder.create(false, true, null);
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
		return serviceFolder;
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.selection = selection;
	}
}
